home *** CD-ROM | disk | FTP | other *** search
/ PC PowerPlay 58 / pcpp58a.iso / extras / quake 3 source / Q3A_ToolSource.exe / Main / glfile.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-02  |  2.0 KB  |  128 lines

  1.  
  2. #include "qbsp.h"
  3.  
  4. int        c_glfaces;
  5.  
  6. int PortalVisibleSides (portal_t *p)
  7. {
  8.     int        fcon, bcon;
  9.  
  10.     if (!p->onnode)
  11.         return 0;        // outside
  12.  
  13.     fcon = p->nodes[0]->opaque;
  14.     bcon = p->nodes[1]->opaque;
  15.  
  16.     // same contents never create a face
  17.     if (fcon == bcon)
  18.         return 0;
  19.  
  20.     if (!fcon)
  21.         return 1;
  22.     if (!bcon)
  23.         return 2;
  24.     return 0;
  25. }
  26.  
  27. void OutputWinding (winding_t *w, FILE *glview)
  28. {
  29.     static    int    level = 128;
  30.     vec_t        light;
  31.     int            i;
  32.  
  33.     fprintf (glview, "%i\n", w->numpoints);
  34.     level+=28;
  35.     light = (level&255)/255.0;
  36.     for (i=0 ; i<w->numpoints ; i++)
  37.     {
  38.         fprintf (glview, "%6.3f %6.3f %6.3f %6.3f %6.3f %6.3f\n",
  39.             w->p[i][0],
  40.             w->p[i][1],
  41.             w->p[i][2],
  42.             light,
  43.             light,
  44.             light);
  45.     }
  46.     fprintf (glview, "\n");
  47. }
  48.  
  49. /*
  50. =============
  51. OutputPortal
  52. =============
  53. */
  54. void OutputPortal (portal_t *p, FILE *glview)
  55. {
  56.     winding_t    *w;
  57.     int        sides;
  58.  
  59.     sides = PortalVisibleSides (p);
  60.     if (!sides)
  61.         return;
  62.  
  63.     c_glfaces++;
  64.  
  65.     w = p->winding;
  66.  
  67.     if (sides == 2)        // back side
  68.         w = ReverseWinding (w);
  69.  
  70.     OutputWinding (w, glview);
  71.  
  72.     if (sides == 2)
  73.         FreeWinding(w);
  74. }
  75.  
  76. /*
  77. =============
  78. WriteGLView_r
  79. =============
  80. */
  81. void WriteGLView_r (node_t *node, FILE *glview)
  82. {
  83.     portal_t    *p, *nextp;
  84.  
  85.     if (node->planenum != PLANENUM_LEAF)
  86.     {
  87.         WriteGLView_r (node->children[0], glview);
  88.         WriteGLView_r (node->children[1], glview);
  89.         return;
  90.     }
  91.  
  92.     // write all the portals
  93.     for (p=node->portals ; p ; p=nextp)
  94.     {
  95.         if (p->nodes[0] == node)
  96.         {
  97.             OutputPortal (p, glview);
  98.             nextp = p->next[0];
  99.         }
  100.         else
  101.             nextp = p->next[1];
  102.     }
  103. }
  104.  
  105. /*
  106. =============
  107. WriteGLView
  108. =============
  109. */
  110. void WriteGLView (tree_t *tree, char *source)
  111. {
  112.     char    name[1024];
  113.     FILE    *glview;
  114.  
  115.     c_glfaces = 0;
  116.     sprintf (name, "%s%s.gl",outbase, source);
  117.     _printf ("Writing %s\n", name);
  118.  
  119.     glview = fopen (name, "w");
  120.     if (!glview)
  121.         Error ("Couldn't open %s", name);
  122.     WriteGLView_r (tree->headnode, glview);
  123.     fclose (glview);
  124.  
  125.     _printf ("%5i c_glfaces\n", c_glfaces);
  126. }
  127.  
  128.